<?php

namespace app\admin\model;

use think\Model;

class OrderItem extends BaseModel
{
    public function product()
    {
        return $this->belongsTo(Product::class, 'product_id', 'id')->bind(['product_name' => 'cname', 'code', 'style_code', 'unit', 'unit_sum']);
    }

    public function warehouse()
    {
        return $this->belongsTo(Warehouse::class, 'warehouse_id', 'id')->bind(['warehouse_name' => 'name']);
    }

    public function invenroty()
    {
        return $this->belongsTo(Inventory::class, 'inventory_id', 'id')->bind(['qty', 'is_futures', 'is_futures_value', 'sales_price', 'actual_price'])->append(['is_futures_value']);
    }

    public function orders()
    {
        return $this->belongsTo(Order::class, 'order_id', 'id')->append(['shipping_address']);
    }

    public function productForOrder()
    {
        return $this->belongsTo(Product::class, 'product_id', 'id')->bind(['product_name' => 'cname', 'style_code', 'unit', 'unit_sum', 'code', 'brand', 'hashrate', 'expiration_date', 'computing_unit', 'billing_weight']);
    }


    public function products()
    {
        return $this->hasOne(Product::class, 'id', 'product_id');
    }

    /* 仓库 */
    public function warehouses()
    {
        return $this->hasOne(Warehouse::class, 'id', 'warehouse_id');
    }
}
